﻿package com.farm.bpm.web.action;

import com.farm.web.easyui.EasyUiUtils;
import java.util.Map;

import com.farm.core.page.CommitType;
import com.farm.core.page.PageSet;
import com.farm.core.page.PageType;
import com.farm.core.sql.query.DBRule;
import com.farm.core.sql.query.DBSort;
import com.farm.core.sql.query.DataQuery;
import com.farm.core.sql.result.DataResult;
import com.farm.web.WebSupport;

/**
 * 实体管理
 * 
 * @author autoCode
 * 
 */
public class ActiontaskhistoryQuery extends WebSupport {
	private Map<String, Object> jsonResult;// 结果集合
	private DataQuery query;// 条件查询
	private PageSet pageset;// 请求状态
	private String ids;// 主键集合

	/**
	 * 查询结果集合
	 * 
	 * @return
	 */
	public String queryall() {
		try {
			query = EasyUiUtils.formatGridQuery(getRequest(), query);
			query = DataQuery
					.init(
							query,
							"act_hi_taskinst a LEFT JOIN act_hi_procinst b ON a.PROC_INST_ID_=b.ID_ LEFT JOIN alone_user c ON c.ID=a.ASSIGNEE_ LEFT JOIN alone_user d ON d.ID=b.START_USER_ID_ LEFT JOIN  act_hi_varinst e ON e.PROC_INST_ID_=b.ID_",
							" a.ID_ AS taskid,a.NAME_ AS taskname,c.NAME AS taskuser,a.START_TIME_ AS taskStartTime,a.END_TIME_ AS taskEndTime,a.DELETE_REASON_ AS deleteReason ,b.ID_ AS instanceId,b.PROC_DEF_ID_ AS processDefId,b.START_TIME_ AS proStartTime,b.END_TIME_ AS proEndTime,d.NAME AS processStartUser,b.DELETE_REASON_ AS processDeleteReason");
			query.setDistinct(true);
			query.setDefaultSort(new DBSort("PROSTARTTIME", "desc"));
			DataResult result = query.search();
			jsonResult = EasyUiUtils.formatGridData(result);
		} catch (Exception e) {
			throw new RuntimeException(e);
		}
		return SUCCESS;
	}

	/**
	 * 跳转
	 * 
	 * @return
	 */
	public String forSend() {
		// TODO 自动生成代码,修改后请去除本注释
		return SUCCESS;
	}

	/**
	 * 显示详细信息（修改或浏览时）
	 * 
	 * @return
	 */
	public String view() {
		try {
			query = EasyUiUtils.formatGridQuery(getRequest(), query);
			query = DataQuery.init(query, "act_hi_varinst",
					" name_ AS NAME ,DOUBLE_,LONG_,TEXT_,TEXT2_");
			query.setDistinct(true);
			query.addRule(new DBRule("PROC_INST_ID_", ids, "="));
			DataResult result = query.search();
			jsonResult = EasyUiUtils.formatGridData(result);
			pageset = new PageSet(PageType.SHOW, CommitType.TRUE);
		} catch (Exception e) {
			pageset = PageSet.initPageSet(pageset, PageType.OTHER,
					CommitType.FALSE, e);
		}
		return SUCCESS;
	}


	// ----------------------------------------------------------------------------------
	public DataQuery getQuery() {
		return query;
	}

	public void setQuery(DataQuery query) {
		this.query = query;
	}

	public PageSet getPageset() {
		return pageset;
	}

	public void setPageset(PageSet pageset) {
		this.pageset = pageset;
	}

	public String getIds() {
		return ids;
	}

	public void setIds(String ids) {
		this.ids = ids;
	}

	public Map<String, Object> getJsonResult() {
		return jsonResult;
	}

	public void setJsonResult(Map<String, Object> jsonResult) {
		this.jsonResult = jsonResult;
	}

//	private static final Logger log = Logger
//			.getLogger(ActiontaskhistoryQuery.class);
	private static final long serialVersionUID = 1L;
	/**
	 * 加载树节点 public String loadTreeNode() { treeNodes =
	 * EasyUiTreeNode.formatAjaxTree(EasyUiTreeNode .queryTreeNodeOne(id,
	 * "SORT", "alone_menu", "ID", "PARENTID", "NAME").getResultList(),
	 * EasyUiTreeNode .queryTreeNodeTow(id, "SORT", "alone_menu", "ID",
	 * "PARENTID", "NAME").getResultList(), "PARENTID", "ID", "NAME"); return
	 * SUCCESS; }
	 * 
	 * @return
	 */
}
